package com.cjm.algorithm.leetcode;

import com.cjm.algorithm.TreeNode;

import java.util.List;

public class MaxDepth104 {
    private int len = 0;
    public int maxDepth1(Node root) {
        if (root == null) return 0;
        len(root, 0);
        return len;
    }

    private void len(Node root, int curlen) {
        if (root == null) return;
        curlen = curlen + 1;
        len = Math.max(curlen, len);
        List<Node> children = root.children;
        if (!children.isEmpty()) {
            for (int i = 0; i < children.size(); i++) {
                len(children.get(i), curlen);
            }
        }
    }

    public static int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return Math.max(maxDepth(root.left), maxDepth(root.right))+1;
    }

    public static void main(String[] args) {
    }
    static class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    };
}
